﻿//Write a method that returns the maximal element in a portion of array of integers starting at given index.
//Using it write another method that sorts an array in ascending / descending order.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _09MaxElementInPortionOfArray
{
    class Program
    {
        static int MaxOfArray(int[] array, int from)
        {
            int maxNum = int.MinValue;
            for (int i = from; i < array.Length; i++)
            {
                if (array[i] > maxNum)
                {
                    maxNum = array[i];
                }
            }
            return maxNum;
        }
        static int[] ArraySort(int[] array)
        {
            int tempIndexHolder;
            for (int i = 0; i < array.Length; i++)
            {
                int temp = MaxOfArray(array, i);
                for (int j = i; j < array.Length; j++)
                {
                    if (temp == array[j])
                    {
                        tempIndexHolder = array[i];
                        array[i] = array[j];
                        array[j] = tempIndexHolder;
                    }
                }
            }
            return array;
        }
        private static void PrintArray(int[] array)
        {
            foreach (var item in ArraySort(array))
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        static void Main(string[] args)
        {
            int[] array = { 1, 2, 3, 4, 5, 6, 4, 4, 3, 2, 3, 4, 2, 1, 4 };
            PrintArray(array);
        }

       
    }
}
